package com.xiaot.shopping.product.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.extension.toolkit.SqlHelper;
import com.xiaot.shopping.product.dao.BrandDao;
import com.xiaot.shopping.product.dao.CategoryBrandRelationDao;
import com.xiaot.shopping.product.dao.CategoryDao;
import com.xiaot.shopping.product.entity.CategoryBrandRelationEntity;
import com.xiaot.shopping.product.service.CategoryBrandRelationService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;


@Service("categoryBrandRelationService")
public class CategoryBrandRelationServiceImpl extends ServiceImpl<CategoryBrandRelationDao, CategoryBrandRelationEntity> implements CategoryBrandRelationService {

    @Resource
    private CategoryDao categoryDao;
    @Resource
    private BrandDao brandDao;

    @Override
    public List<CategoryBrandRelationEntity> queryPage(Long brandId) {

        return this.list(new QueryWrapper<CategoryBrandRelationEntity>().eq("brand_id", brandId));
    }

    @Override
    public boolean saveRelation(CategoryBrandRelationEntity entity) {
        entity.setCatelogName(categoryDao.selectById(entity.getCatelogId()).getName());
        entity.setBrandName(brandDao.selectById(entity.getBrandId()).getName());
        return SqlHelper.retBool(getBaseMapper().insert(entity));
    }
}